<template>
  <el-row v-loading="loading">
    <el-col :span="24">
      <el-row class="search-row">
        <el-col :span="12">
          <el-input placeholder="请输入档案号/姓名" size="small" v-model="like1" style="width: 260px;">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
          <div style="height: 30px;">
          </div>
        </el-col>
        <el-col :span="12" style="text-align: right;">
          <el-button type="primary" icon="el-icon-plus" size="small" @click="add">新增</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">

          <el-table :data="findOrder().slice((pageNum-1)*pageSize,pageNum*pageSize)" border size="mini" header-cell-class-name="header-row">
            <el-table-column prop="id" label="序号" header-align="center" align="center"></el-table-column>
            <el-table-column prop="returnTime" label="回访日期" header-align="center" align="center"></el-table-column>
            <el-table-column prop="interposeName" label="被干预人" header-align="center" align="center"></el-table-column>
            <el-table-column prop="tHealthmgr.healthMgrName" label="回访人员" header-align="center" align="center"></el-table-column>
            <el-table-column prop="visitMethod" label="方式" header-align="center" align="center"></el-table-column>
            <el-table-column prop="returnContent" label="回访内容" header-align="center" align="center"></el-table-column>
            <el-table-column prop="feedbackInfo" label="反馈信息" header-align="center" align="center"></el-table-column>
            <el-table-column prop="handlingResult" label="处理结果" header-align="center" align="center"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center">
              <template slot-scope="scope">
                <el-button type="danger" size="mini"
                  v-if="scope.row.gyStatue=='未结束'"
                  @click="js(scope.row)">结束干预</el-button>
                <span v-if="scope.row.gyStatue=='已结束'">干预结束</span>
              </template>
            </el-table-column>
        </el-table>
        </el-col>
        <el-col :span="24">
          <el-pagination
            background
            @size-change="handleSizeChange"
            :current-page.sync="pageNum"
            :page-sizes="[2,4,6,8]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="findOrder().length">
          </el-pagination>
          <el-dialog title="添加" :visible.sync="dialogTransferVisible">
              <el-form :model="visit" :rules="rules" label-position="right" size="small">
                <el-form-item label="档案号" prop="fileNumber">
                    <el-input placeholder="档案号" @blur="getName" size="small" v-model="visit.fileNumber" style="width: 235px;"/>
                  </el-form-item>
                  <el-form-item label="被干预人" prop="interposeName">
                    <el-input placeholder="被干预人" size="small" v-model="visit.interposeName" style="width: 235px;" :disabled="true"/>
                  </el-form-item>

                   <el-form-item label="干预人" prop="healthMgrId">
                     <el-select v-model="visit.healthMgrId" placeholder="请选择">
                    <el-option
                      v-for="item in jksList"
                      :key="item.healthMgrId"
                      :label="item.healthMgrName"
                      :value="item.healthMgrId">
                    </el-option>
                  </el-select>
                  </el-form-item>

                    <el-form-item label="回访时间" prop="returnTime">
                    <el-col :span="5">
                      <el-date-picker
                        style="width: 200px;"
                        v-model="visit.returnTime"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd">
                      </el-date-picker>
                    </el-col>
                    <el-col class="line" :span="2">-</el-col>
                    <el-col :span="5">
                      <el-time-picker type="date" placeholder="选择时间" v-model="visit.specificTime" style="width: 200px;" value-format="HH:mm:ss"></el-time-picker>
                    </el-col>
                  </el-form-item>


                  <el-form-item label="干预方式" prop="visitMethod">
                    <el-input placeholder="干预方式" size="small" v-model="visit.visitMethod" style="width: 235px;"/>
                  </el-form-item>


                  <el-form-item label="回访内容" prop="returnContent">
                    <el-input
                    style="width: 630px;"
                    type="textarea"
                    :rows="2"
                    placeholder="请输入回访内容"
                    v-model="visit.returnContent">
                  </el-input>
                  </el-form-item>

                  <el-form-item label="反馈信息" prop="feedbackInfo">
                    <el-input
                      style="width: 630px;"
                      type="textarea"
                      :rows="2"
                      placeholder="请输入反馈信息"
                      v-model="visit.feedbackInfo">
                    </el-input>
                  </el-form-item>
                  <el-form-item label="处理结果" prop="handlingResult">
                    <el-input
                      style="width: 630px;"
                      type="textarea"
                      :rows="2"
                      placeholder="请输入处理结果"
                      v-model="visit.handlingResult">
                    </el-input>
                  </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="qd">确 定</el-button>
              <el-button @click="dialogTransferVisible=false">取消</el-button>
            </div>
          </el-dialog>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import {getAll,getName,updateVisit,jsgy} from '@/api/xsxtnterposeFollowupVisit'
import {listAllJks,getHealthMgrId} from '@/api/xsxhealthmgr'



export default {
  data() {
      return {
        userId:0,
        jksList:[],
        hfList:[],
        dialogTransferVisible:false,
        loading: false,
        like1:'',
        pageSize:4,//每页显示的条数
        pageNum:1,
        visit:{
          id:0,
          healthMgrId:'',
          interposeName:'',
          fileNumber:'',
          returnTime:'',
          specificTime:'',
          visitMethod:'',
          returnContent:'',
          feedbackInfo:'',
          handlingResult:''
        },
         rules: {
          fileNumber: [
            { required: true, message: '请输入档案号', trigger: 'blur' },
            { min: 2, message: '长度在 2 个字符以上', trigger: 'blur' }
          ],
          interposeName: [
            { required: true, message: '请输入被干预人', trigger: 'blur' },
            { min: 2, message: '长度在 2 个字符以上', trigger: 'blur' }
          ],
          healthMgrId: [
            {required: true, message: '请选择干预人', trigger: 'change' }
          ],
          returnTime: [
            {required: true, message: '请输入回访时间', trigger: 'blur' }
          ],
          visitMethod: [
            {required: true, message: '请输入干预方式', trigger: 'blur' }
          ],
          returnContent: [
            { required: true, message: '请输入回访内容', trigger: 'blur' }
          ],
          feedbackInfo: [
            { required: true, message: '请输入反馈信息', trigger: 'blur' }
          ],
          costJiage: [
            { required: true, message: '请输入项目成本', trigger: 'blur' }
          ],
          handlingResult: [
            { required: true, message: '请输入处理结果', trigger: 'blur' }
          ]
        },
      };
  },
  methods: {
    js(row){
      let jks=row.healthMgrId;
      jsgy(row.id,jks).then(response => {
        if(response.data>0){
          this.pageInit()
        }
      })
    },
    handleSizeChange(val) {
     this.pageSize = val;
    },
    add(){
      this.dialogTransferVisible=true;

    },
    getName(){
      getName(this.visit.fileNumber).then(response => {
        if(response.data!=''){
          this.visit=response.data
        }
      })
    },
    async pageInit() {
      let userid=JSON.parse(sessionStorage.getItem('currentUser')).id
      try {
        let [ttyy,jks] = await Promise.all([
          getHealthMgrId(userid),
          listAllJks()
        ])
        this.userId=ttyy.data
        this.jksList=jks.data
        getAll(this.userId).then(response => {
          this.hfList=response.data
        })
        console.log(jg.data)
      } catch(error) {
        this.outputError(error)
      }
    },
    findOrder(){
        return this.hfList.filter((item,i)=>{
            if(item.fileNumber.includes(this.like1) || item.interposeName.includes(this.like1)){
                return item;
            }
        })
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    qd(){
       updateVisit(this.visit).then(response => {
        if(response.data>0){
          this.pageInit()
        }
      })
      this.dialogTransferVisible=false;

    },
  },
  created() {
    this.pageInit()
  }
}
</script>
